﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyList
{
    class MyList<T>
    {
        T[] list;
        public MyList(int capacity = 10)
        {
            list = new T[capacity];
        }
        public T this[int i]
        {
            get => list[i];
            set => list[i] = value;
        }
        public int Length { get => list.Length; }
        public void ForEach(Action<T> action)
        {
            foreach (T i in list)
            {
                action(i);
            }
        }
        public T ForEach(Func<T, T, T> func)
        {
            if (list.Length == 0) return default;
            T res = list[0];
            for (int i = 1; i < list.Length; i++)
            {
                res = func(res, list[i]);
            }
            return res;
        }
    }
}
